using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.IO;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml;
public class HL_Admin_Admin_TemProjectInstall : Admin, IRequiresSessionState
{
	protected DropDownList FileList;
	protected Label conlist;
	protected Literal RootList;
	protected Literal FileNamelist;
	protected TextBox filename;
	protected Button OK;
	protected HtmlForm form1;
	protected string DefaultPath = "";
	protected string bojText = "ss";
	protected string style = "0";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.admin.CheckAdminPower(11))
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Template");
			base.WriteRightErrMsg();
		}
		this.bojText = base.Request["obj"];
		this.BingFile(base.Request["path"]);
		this.style = base.Request["style"];
		this.FileList.Attributes.Add("onchange", "infiler(this.value)");
	}
	protected void BingFile(string path)
	{
		string s = "";
		string text = null;
		text = this.InstallDir;
		if (string.IsNullOrEmpty(text))
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Template/ProjPathErr"), "");
		}
		string path2 = Fetch.GetTruePath(text) + path;
		DirectoryInfo directoryInfo;
		try
		{
			directoryInfo = new DirectoryInfo(path2);
		}
		catch
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Template/PathErr"), "");
			return;
		}
		if (path != "" && path != null && path.LastIndexOf('\\') > 0)
		{
			s = path.Remove(path.LastIndexOf('\\'));
		}
		if (this.style == "1")
		{
			this.FileNamelist.Text = "";
		}
		else
		{
			this.FileNamelist.Text = "<div class=\"filel\" onclick=\"return infiler('" + base.Server.UrlEncode(s) + "')\">上一级</div>";
		}
		this.conlist.Text = "<img class=\"upbt\" onmouseover=\"this.className='upbt2'\" onmouseout=\"this.className='upbt'\" title=\"返回上一级\" src=\"Images/restore_f2.png\" border=0 onclick=\"return infiler('" + base.Server.UrlEncode(s) + "')\" />";
		if (directoryInfo.Exists)
		{
			string a = "";
			string[] array = null;
			DirectoryInfo directoryInfo2 = new DirectoryInfo(Fetch.GetTruePath(text));
			if (path != null && path != "")
			{
				array = path.Split(new char[]
				{
					'\\'
				});
				if (array != null)
				{
					a = array[1];
				}
			}
			DirectoryInfo[] directories = directoryInfo2.GetDirectories();
			for (int i = 0; i < directories.Length; i++)
			{
				DirectoryInfo directoryInfo3 = directories[i];
				ListItem listItem = new ListItem();
				listItem.Text = directoryInfo3.Name;
				listItem.Value = base.Server.UrlEncode("\\" + directoryInfo3.Name);
				if ("\\" + directoryInfo3.Name == path)
				{
					listItem.Selected = true;
				}
				this.FileList.Items.Add(listItem);
				Literal expr_259 = this.RootList;
				expr_259.Text += "<div ";
				if ("\\" + directoryInfo3.Name == path)
				{
					Literal expr_297 = this.RootList;
					expr_297.Text += " class=\"floer2\" ";
				}
				else
				{
					Literal expr_2BA = this.RootList;
					expr_2BA.Text += " class=\"floer\" ";
				}
				Literal expr_2D7 = this.RootList;
				string text2 = expr_2D7.Text;
				expr_2D7.Text = string.Concat(new string[]
				{
					text2,
					"><img src=\"images/folder_icon.gif\" border=0/>&nbsp;<a href=\"?style=1&obj=",
					this.bojText,
					"&path=\\",
					base.Server.UrlEncode(directoryInfo3.Name),
					"\">",
					directoryInfo3.Name,
					"</a></div>"
				});
				if (a != "")
				{
					if (a == directoryInfo3.Name)
					{
						if (array != null)
						{
							string str = "\\" + directoryInfo3.Name;
							for (int j = 2; j < array.Length; j++)
							{
								listItem = new ListItem();
								for (int k = 0; k < j; k++)
								{
									ListItem expr_3D4 = listItem;
									expr_3D4.Text += ".";
								}
								ListItem expr_3FD = listItem;
								expr_3FD.Text += array[j];
								listItem.Value = base.Server.UrlEncode(str + "\\" + array[j]);
								if (j + 1 == array.Length)
								{
									listItem.Selected = true;
								}
								this.FileList.Items.Add(listItem);
								str = str + "\\" + array[j];
							}
						}
					}
				}
			}
			directories = directoryInfo.GetDirectories();
			for (int i = 0; i < directories.Length; i++)
			{
				DirectoryInfo directoryInfo3 = directories[i];
				Literal expr_4DB = this.FileNamelist;
				string text2 = expr_4DB.Text;
				expr_4DB.Text = string.Concat(new string[]
				{
					text2,
					"<div class=\"floer\"><img src=\"images/folder_icon.gif\" border=0/>&nbsp;<a href=\"javascript:void(0)\" onClick=\"return Clickfiler('",
					directoryInfo3.Name,
					"')\" ondblclick=\"return infiler('",
					base.Server.UrlEncode(path + "\\" + directoryInfo3.Name),
					"')\">",
					directoryInfo3.Name,
					"</a></div>"
				});
			}
			FileInfo[] files = directoryInfo.GetFiles();
			for (int i = 0; i < files.Length; i++)
			{
				FileInfo fileInfo = files[i];
				string a2 = fileInfo.Name.Substring(fileInfo.Name.LastIndexOf('.')).ToLower();
				if (a2 == ".config")
				{
					Literal expr_5EB = this.FileNamelist;
					string text2 = expr_5EB.Text;
					expr_5EB.Text = string.Concat(new string[]
					{
						text2,
						"<div class=\"filel\"><img src=\"images/install.png\" width=16 height=16 border=0/>&nbsp;<a href=\"javascript:void(0)\" onClick=\"return Clickfile('",
						fileInfo.Name,
						"')\" >",
						fileInfo.Name.Remove(fileInfo.Name.LastIndexOf('.')),
						"</a></div>"
					});
				}
			}
			if (path != null)
			{
				this.DefaultPath = path.Replace("\\", "\\\\");
			}
		}
	}
	protected void InstallButton_OnClick(object sender, EventArgs e)
	{
		string text = this.filename.Text;
		if (!string.IsNullOrEmpty(text))
		{
			XmlDocument xmlDocument = new XmlDocument();
			try
			{
				xmlDocument.Load(Fetch.GetTruePath(text));
			}
			catch (Exception ex)
			{
				this.WriteErrMsg("", Language.GetAdminMsg("TemplateProject/InstallErr", ex.Message.ToString()), "");
			}
			TemProjectBll temProjectBll = new TemProjectBll(this.conn);
			int startIndex = text.LastIndexOf('\\');
			string text2 = text.Substring(startIndex);
			int startIndex2 = text2.LastIndexOf('.');
			text2 = text2.Remove(startIndex2);
			text2 = text2.Replace("\\", "");
			text2 = text2.Replace("/", "");
			if (temProjectBll.GetProjectByName(text2).Rows.Count > 0)
			{
				this.WriteErrMsg("", Language.GetAdminMsg("TemplateProject/InstallErr", "方案已存在！"), "");
			}
			string text3 = text.Remove(startIndex) + "/";
			text3 = text3.Replace("\\", "/");
			text3 = "<TemplateDir>" + text3 + "</TemplateDir>";
			string text4 = xmlDocument.DocumentElement.InnerXml.ToString();
			text4 = text3 + text4;
			string innerText = xmlDocument.DocumentElement.SelectSingleNode("Intro").InnerText;
			string innerText2 = xmlDocument.DocumentElement.SelectSingleNode("SkinDir").InnerText;
			temProjectBll.AddProject(text2, innerText, text4, 0, innerText2);
			this.InstallSkin(xmlDocument, text2, innerText2);
		}
		else
		{
			this.WriteErrMsg("", Language.GetAdminMsg("TemplateProject/InstallErr", "文件名空！"), "");
		}
		this.WriteSuccessMsg("", Language.GetAdminMsg("TemplateProject/InstallSuccess"), "javascript:{opener.location.reload();}");
	}
	protected void InstallSkin(XmlDocument xml, string ProjectName, string SkinDir)
	{
		XmlElement documentElement = xml.DocumentElement;
		XmlNodeList xmlNodeList = documentElement.SelectNodes("Skin/Item");
		SkinBll skinBll = new SkinBll(this.conn);
		foreach (XmlNode xmlNode in xmlNodeList)
		{
			try
			{
				string innerText = xmlNode.SelectSingleNode("SkinName").InnerText;
				string innerText2 = xmlNode.SelectSingleNode("SkinPath").InnerText;
				string innerText3 = xmlNode.SelectSingleNode("SkinType").InnerText;
				string innerText4 = xmlNode.SelectSingleNode("IsDefault").InnerText;
				string innerText5 = xmlNode.SelectSingleNode("SkinPreviewImg").InnerText;
				bool isDefault = innerText4 == "1";
				skinBll.AddSkin(innerText, null, isDefault, false, ProjectName, innerText3, SkinDir, innerText2, innerText5);
			}
			catch
			{
				this.WriteErrMsg("", Language.GetAdminMsg("TemplateProject/InstallErr", "格式错误，安装中断！"), "");
			}
		}
	}
}
